<?php
namespace App\Http\Controllers\Api\v2;

use App\Http\Controllers\Api\v2\AstroController;
use App\Http\Controllers\Api\BaseController;
use App\Http\Controllers\Api\v2\NatalController;
use App\Http\Controllers\Api\v2\NowController;
use App\Http\Controllers\Api\v2\FirdariaController;
use App\Http\Controllers\Api\v2\SynastryController;
use App\Http\Controllers\Api\v2\ProfectionController;
use App\Models\Api\Recode;

use Illuminate\Http\Request;
class AstroDataController extends BaseController
{
    protected $Astro;

    public function __construct()
    {
        parent::__construct();
        $this->Astro = new AstroController();
    }

    /**
     * 获取星盘配置
     */
    public function read(Request $request)
    {
         $datetime = htmlspecialchars($request->input('datetime'));
         $id = $request->input('id',0);
         $timezone = $request->input('timezone',8);
         $chart = htmlspecialchars($request->input('chart'));
         $tid = $request->input('tid',1);
         $longitude = number_format(floatval($request->input('longitude')),8);
         $latitude = number_format(floatval($request->input('latitude')),8);

         $id1 = $request->input('id1');
         $id2 = $request->input('id2');


         switch ($chart)
         {
             case 'now':
                 $nowModel =  new NowController();
                 $details = $nowModel->get(['tid'=>$tid,'timezone'=>$timezone,'longitude'=>$longitude,'latitude'=>$latitude,'datetime'=>$datetime]);
                 return show(config('code.success'),'Success.',$details);
                 break;
             case 'natal':
                 $natalModel = new NatalController();
                 $details = $natalModel->get(['id'=>$id,'tid'=>$tid]);
                 return show(config('code.success'),'Success',$details);
                 break;
             case 'transits':
                 $details =  $this->Astro->transits($datetime,$timezone,$id,$tid,true);
                 return show(config('code.success'),'Success',$details);
                 break;
             case 'thirdprogressed':
                 $details = $this->Astro->thirdprogressed($datetime,false,$timezone,$id,$tid,true);
                 return show(config('code.success'),'Success',$details);
                 break;
             case 'progressions':
                 $details = $this->Astro->progressions(['datetime'=>$datetime,'timezone'=>$timezone,'id'=>$id,'tid'=>$tid]);
                 return show(config('code.success'),'Success.',$details);
                 break;
             case 'progressionsvsnatal':
                 $details = $this->Astro->progressionsvsnatal(['datetime'=>$datetime,'timezone'=>$timezone,'id'=>$id,'tid'=>$tid]);
                 return show(config('code.success'),'Success.',$details);
                 break;
             case 'solar':
                 $details = $this->Astro->solar(['datetime'=>$datetime,'timezone'=>$timezone,'id'=>$id,'tid'=>$tid]);
                 return show(config('code.success'),'Success.',$details);
                 break;
             case 'solar_return':
                 $details = $this->Astro->solar_return(['datetime'=>$datetime,'timezone'=>$timezone,'id'=>$id,'tid'=>$tid]);
                 return show(config('code.success'),'Success.',$details);
                 break;
             case 'lunar_return':
                 $details = $this->Astro->lunar_return(['datetime'=>$datetime,'timezone'=>$timezone,'id'=>$id,'tid'=>$tid]);
                 return show(config('code.success'),'Success.',$details);
                 break;
             case 'firdaria':
                 $firdariaModel = new FirdariaController();
                 $details = $firdariaModel->get(['datetime'=>$datetime,'timezone'=>$timezone,'id'=>$id,'tid'=>$tid]);
                 return show(config('code.success'),'Success.',$details);
                 break;
             case 'profection':
                 $profectionModel = new ProfectionController();
                 $details = $profectionModel->get(['datetime'=>$datetime,'timezone'=>$timezone,'id'=>$id,'tid'=>$tid]);
                 return show(config('code.success'),'Success.',$details);
                 break;
             case 'synastry':
                 $synastryModel = new SynastryController();
                 $details = $synastryModel->get(['id1'=>$id1,'id2'=>$id2,'tid'=>$tid]);
                 return show(config('code.success'),'Success.',$details);
                 break;
             case 'composite':
                 $details = $this->Astro->composite(['id1'=>$id1,'id2'=>$id2,'tid'=>$tid]);
                 return show(config('code.success'),'Success.',$details);
                 break;
             case 'composite_thirdprogressed':
                 $details = $this->Astro->composite_thirdprogressed(['datetime'=>$datetime,'timezone'=>$timezone,'id1'=>$id1,'id2'=>$id2,'tid'=>$tid]);
                 return show(config('code.success'),'Success.',$details);
                 break;
             case 'composite_progressions':
                 $details = $this->Astro->composite_progressions(['datetime'=>$datetime,'timezone'=>$timezone,'id1'=>$id1,'id2'=>$id2,'tid'=>$tid]);
                 return show(config('code.success'),'Success.',$details);
                 break;
             case 'davison':
                 $details = $this->Astro->davison(['id1'=>$id1,'id2'=>$id2,'tid'=>$tid]);
                 return show(config('code.success'),'Success.',$details);
                 break;
             case 'marks':
                 $details = $this->Astro->marks(['id1'=>$id1,'id2'=>$id2,'tid'=>$tid]);
                 return show(config('code.success'),'Success.',$details);
                 break;
         }

    }
}
